package com.cq.hd.member.controller;

import com.cq.hd.common.pagination.Page;
import com.cq.hd.common.response.Result;
import com.cq.hd.common.response.ResultGenerator;
import com.cq.hd.member.api.TbBusinessApi;
import com.cq.hd.member.api.dto.*;
import com.cq.hd.member.api.vo.*;

import com.cq.hd.member.service.TbBusinessService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 商家表 前端控制器
 * </p>
 *
 * @author mYunYu
 * @since 2023-11-21
 */
@RestController
public class TbBusinessController implements TbBusinessApi {

    @Autowired
    private TbBusinessService businessService;

    @ApiOperation(value = "商家列表")
    @ApiResponse(response = BusinessPageVo.class, code = 200, message = "接口返回对象参数")
    @Override
    public Result<Page<BusinessPageVo>> pageBusiness(BusinessPageDto businessPageDto) {
        return ResultGenerator.success(businessService.pageBusiness(businessPageDto));
    }

    @ApiOperation(value = "商家详情")
    @ApiImplicitParam(name = "id", value = "商家id", required = true, paramType = "query", dataType = "Long")
    @ApiResponse(response = AdminBusinessPageVo.class, code = 200, message = "接口返回对象参数")
    @Override
    public Result<AdminBusinessPageVo> details(Long id) {
        return ResultGenerator.success(businessService.details(id));
    }

    @ApiOperation(value = "商家邀请商户/经纪人")
    @ApiImplicitParam(name = "businessInviteDto", value = "实体", required = true, paramType = "body", dataType = "BusinessInviteDto")
    @ApiResponse(response = InviteMerchantVo.class, code = 200, message = "接口返回对象参数")
    @Override
    public Result<InviteMerchantVo> invite(@RequestBody BusinessInviteDto businessInviteDto) {
        return ResultGenerator.success(businessService.invite(businessInviteDto));
    }

    @ApiOperation(value = "商家解绑商户")
    @ApiImplicitParam(name = "businessMerchantUnBindDto", value = "实体", required = true, paramType = "body", dataType = "BusinessMerchantUnBindDto")
    @Override
    public Result<Boolean> unBindMerchant(@RequestBody BusinessMerchantUnBindDto businessMerchantUnBindDto) {
        return ResultGenerator.success(businessService.unBindMerchant(businessMerchantUnBindDto));
    }

    @ApiOperation(value = "分页关联商户列表")
    @ApiImplicitParam(name = "relationMerchantPageDto", value = "实体", required = true, paramType = "query", dataType = "RelationMerchantPageDto")
    @ApiResponse(response = RelationMerchantPageVo.class, code = 200, message = "接口返回对象参数")
    @Override
    public Result<Page<RelationMerchantPageVo>> pageRelationMerchant(RelationMerchantPageDto relationMerchantPageDto) {
        return ResultGenerator.success(businessService.pageRelationMerchant(relationMerchantPageDto));
    }

    @ApiOperation(value = "关联商户id列表")
    @ApiResponse(response = Long.class, code = 200, message = "接口返回对象参数")
    @Override
    public Result<List<Long>> listRelationMerchantId(Long userId, Long businessId) {
        return ResultGenerator.success(businessService.listRelationMerchantId(userId, businessId));
    }

    @ApiOperation(value = "根据用户id获取商家信息")
    @ApiImplicitParam(name = "userId", value = "用户id", required = true, paramType = "query", dataType = "Long")
    @ApiResponse(response = BusinessPageVo.class, code = 200, message = "接口返回对象参数")
    @Override
    public Result<BusinessPageVo> getByUserId(Long userId) {
        return ResultGenerator.success(businessService.getByUserId(userId));
    }

    @ApiOperation(value = "商家主页")
    @ApiImplicitParam(name = "id", value = "商家id", required = true, paramType = "query", dataType = "Long")
    @ApiResponse(response = BusinessHomePageVo.class, code = 200, message = "接口返回对象参数")
    @Override
    public Result<BusinessHomePageVo> getHomePage(Long id, Long userId) {
        return ResultGenerator.success(businessService.getHomePage(id, userId));
    }

    @ApiOperation(value = "更新商家主页")
    @ApiImplicitParam(name = "updateHomePageDto", value = "实体", required = true, paramType = "body", dataType = "UpdateHomePageDto")
    @Override
    public Result<Boolean> updateHomePage(@RequestBody UpdateHomePageDto updateHomePageDto) {
        return ResultGenerator.success(businessService.updateHomePage(updateHomePageDto));
    }

    @ApiOperation(value = "分享商家主页")
    @ApiImplicitParam(name = "id", value = "商家id", required = true, paramType = "body", dataType = "Long")
    @ApiResponse(response = BusinessShareVo.class, code = 200, message = "接口返回对象参数")
    @Override
    public Result<BusinessShareVo> shareHomePage(@RequestBody BusinessShareDto businessShareDto) {
        return ResultGenerator.success(businessService.shareHomePage(businessShareDto));
    }

    @ApiOperation(value = "根据手机号获取商家信息")
    @ApiImplicitParam(name = "mobile", value = "手机号", required = true, paramType = "query", dataType = "String")
    @ApiResponse(response = BusinessPageVo.class, code = 200, message = "接口返回对象参数")
    @Override
    public Result<BusinessPageVo> getByMobile(String mobile) {
        return ResultGenerator.success(businessService.getByMobile(mobile));
    }

    @ApiOperation(value = "根据id批量查询商家数据")
    @ApiResponse(response = BusinessVo.class, code = 200, message = "接口返回对象参数")
    @Override
    public Result<List<BusinessVo>> listByIds(List<Long> ids) {
        return ResultGenerator.success(businessService.listBusinessByIds(ids));
    }

    @ApiOperation(value = "根据商家名称分页搜索商家数据")
    @ApiResponse(response = BusinessVo.class, code = 200, message = "接口返回对象参数")
    @Override
    public Result<Page<BusinessVo>> searchByBusinessName(Integer pageNum, Integer pageSize, String keyword) {
        return ResultGenerator.success(businessService.searchByBusinessName(pageNum, pageSize, keyword));
    }

    @ApiOperation(value = "获取活动发布次数")
    @ApiResponse(response = Integer.class, code = 200, message = "接口返回对象参数")
    @Override
    public Result<BusinessVo> getActiveCount(Long userId, Long businessId) {
        return ResultGenerator.success(businessService.getActiveCount(userId, businessId));
    }

    @ApiOperation(value = "扣减商家发布活动个数")
    @ApiImplicitParam(name = "updateActiveCountDto", value = "实体", required = true, paramType = "body", dataType = "UpdateActiveCountDto")
    @ApiResponse(response = Boolean.class, code = 200, message = "接口返回对象参数")
    @Override
    public Result<Boolean> subActiveCount(@RequestBody UpdateActiveCountDto updateActiveCountDto) {
        return ResultGenerator.success(businessService.subActiveCount(updateActiveCountDto));
    }

    @ApiOperation(value = "扫描商家会员是否过期")
    @Override
    public Result<Boolean> scanBusinessMemberExpireJob() {
        return ResultGenerator.success(businessService.scanBusinessMemberExpireJob());
    }

    @ApiOperation(value = "根据邀请码获取商家数据")
    @Override
    public Result<BusinessPageVo> getByInviteCode(String inviteCode) {
        return ResultGenerator.success(businessService.getByInviteCode(inviteCode));
    }

    @ApiOperation(value = "根据日期查询新入驻的商家数")
    @Override
    public Result<Integer> getNewCountByDate(String startTime, String endTime) {
        return ResultGenerator.success(businessService.getNewCountByDate(startTime, endTime));
    }

    @ApiOperation(value = "根据商家id获取商家数据")
    @Override
    public Result<BusinessPageVo> getById(Long businessId) {
        return ResultGenerator.success(businessService.getBusinessById(businessId));
    }

    @ApiOperation(value = "批量获取商家详情数据")
    @Override
    public Result<List<BusinessDetailVo>> listDetailByIds(@RequestBody List<Long> businessIds) {
        return ResultGenerator.success(businessService.listDetailByIds(businessIds));
    }

    @ApiOperation(value = "扣减商家补贴金余额+增加商家补贴金流水（两条，一条是补贴扣除，一条是营销补贴服务费）")
    @Override
    public Result<Boolean> subSubsidyAmt(@RequestBody BusinessSubSubsidyAmtDto businessSubSubsidyAmtDto) {
        return ResultGenerator.success(businessService.subSubsidyAmt(businessSubSubsidyAmtDto));
    }

    @ApiOperation(value = "扫描 结算池商家 对 普通商户 的待转账记录，扣减商家补贴余额，如果扣减成功，另一个任务回去定时进行汇付余额转账")
    @Override
    public Result<Boolean> scanSubsidyWaitPayJob() {
        businessService.scanSubsidyWaitPayJob();
        return ResultGenerator.success(true);
    }

    @ApiOperation(value = "扫描 结算池商家 对 普通商户 的待转账记录，扣减商家补贴余额，如果扣减成功，另一个任务回去定时进行汇付余额转账")
    @Override
    public Result<Boolean> scanSubsidyWaitTransferJob() {
        businessService.scanSubsidyWaitTransferJob();
        return ResultGenerator.success(true);
    }

    @ApiOperation(value = "商家分享海报是否展示商家头像开关")
    @Override
    public Result<Integer> updatePosterShowAvatarState(Long businessId, Integer posterShowAvatarState) {
        return ResultGenerator.success(businessService.updatePosterShowAvatarState(businessId, posterShowAvatarState));
    }
}
